package com.cvai.controller;


import com.cvai.R.Result;
import com.cvai.context.BaseContext;
import com.cvai.domain.dto.KnowledgeDto;
import com.cvai.domain.po.Knowledge;
import com.cvai.service.IKnowledgeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cv
 * @since 2025-03-14
 */
@RestController
@RequestMapping("/knowledge")
@RequiredArgsConstructor
public class KnowledgeController {
    private final IKnowledgeService knowledgeService;
    @PostMapping
    public Result add(@RequestBody KnowledgeDto knowledgeDto) {
        knowledgeService.add(knowledgeDto);
        return Result.success();
    }

    @GetMapping
    public Result list() {
        return Result.success(knowledgeService.list(knowledgeService.lambdaQuery().getWrapper().eq(Knowledge::getUserId, BaseContext.getCurrentUser().getId())));
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable Long id) {
        knowledgeService.delById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Flux<String> chat(@PathVariable Long id, @RequestParam String question) {
        return knowledgeService.chat(id, question);
    }
}
